// function getFutureTimePeriods() {
//   const currentTime = new Date()

//   // 获取未来三十分钟后的时间
//   currentTime.setMinutes(new Date().getMinutes() + 30)

//   // 计算距离下一个二十分钟时段的分钟数
//   const minutesToNextTimePeriod = 20 - (currentTime.getMinutes() % 20)

//   // 初始化时间段数组
//   const timePeriods = []

//   // 循环生成时间段
//   let startTime = new Date(currentTime.getTime() + minutesToNextTimePeriod * 60000)

//   while (startTime.getDate() === currentTime.getDate()) {
//     const endTime = new Date(startTime.getTime() + 20 * 60000)
//     timePeriods.push({
//       start: startTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
//       end: endTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
//     })
//     startTime = endTime
//   }

//   return timePeriods
// }

// // 测试方法
// const timePeriods = getFutureTimePeriods()
// timePeriods.forEach(({ start, end }) => {
//   console.log(`${start} - ${end}`)
// })

function getAllTimePeriods() {
  const timePeriods = []

  for (let i = 0; i < 24; i++) {
    timePeriods.push(
      {
        start: `${i.toString().padStart(2, "0")}:00`,
        end: `${i.toString().padStart(2, "0")}:20`,
      },
      {
        start: `${i.toString().padStart(2, "0")}:20`,
        end: `${i.toString().padStart(2, "0")}:40`,
      },
      {
        start: `${i.toString().padStart(2, "0")}:40`,
        end: `${(i + 1 === 24 ? 0 : i + 1).toString().padStart(2, "0")}:00`,
      }
    )
  }

  const currentTime = new Date()
  const earliestTime = new Date(currentTime.getTime() + 30 * 60000)

  return timePeriods
    .filter(({ start }) => {
      const time = new Date()
      const [hours, minutes] = start.split(":")
      time.setHours(Number(hours), Number(minutes), 0, 0)
      return time >= earliestTime
    })
    .map(({ start, end }) => {
      return `${start} - ${end}`
    })
}

// 获取当前时间加半个小时到零点每隔 20 分钟的所有时间区间，分钟数要向上取十的整倍数
function getAvailableTimePeriods() {
  const startTime = new Date()

  // 分钟数向上取十的整倍数并延后三十分钟
  startTime.setMinutes(Math.ceil(startTime.getMinutes() / 10) * 10 + 30)

  const endTime = new Date()

  endTime.setDate(new Date().getDate() + 1)

  endTime.setHours(0, 0, 0, 0)

  const timePeriods = []

  while (startTime.getTime() + 20 * 60 * 1000 < endTime) {
    const start = startTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })

    startTime.setMinutes(startTime.getMinutes() + 20)
    const end = startTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" })

    // timePeriods.push({ start, end })
    timePeriods.push(`${start} - ${end}`)
  }

  console.log(timePeriods)
}

getAvailableTimePeriods()
